package com.hs.telepass.controller.task;


import android.content.Intent;
import com.hs.telepass.controller.TaskController;
import com.hs.telepass.model.RepositoryProfile;
import com.hs.telepass.utils.JsonUtil;

public class GetProfileInfoTask extends Task{
    public final static String ACTION_GET_PROFILE_INFO_TASK = "action_get_profile_info_task";

    private String jsonRequstStr;
    private String taskUrl;
    private int requestType;

    public GetProfileInfoTask(String serviceId, String serviceName){
        requestType = TASK_REQUST_TYPE_POST;
        taskUrl = BASE_API_URL + "/app/repo/" + serviceId + "/" + serviceName + "/" + "repository.js";
    }

    @Override
    public void onExecuted(String response, int httpCode) {
        Intent intent = new Intent(getActionName());
        RepositoryProfile json = JsonUtil.fromJson(response, RepositoryProfile.class);
        if("410".equals(json.getCode())){
            intent.putExtra(TaskController.EXTRA_EVENT, TaskController.EVENT_TASK_ERROR);
        }else{
            intent.putExtra(TaskController.EXTRA_EVENT, TaskController.EVENT_TASK_SUCCEED);
            intent.putExtra(TaskController.EXTRA_RESPONSE, json);
        }
        broadcastManager.sendBroadcast(intent);
    }

    @Override
    public int getRequstType() {
        return requestType;
    }

    @Override
    public String getJsonRequstStr() {
        return jsonRequstStr;
    }

    @Override
    public int getResponseSuccessCode() {
        return 0;
    }

    @Override
    public String getTaskUrl() {
        return taskUrl;
    }

    @Override
    public String getActionName() {
        return ACTION_GET_PROFILE_INFO_TASK;
    }
}
